/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.mapper;

import cn.webrx.entity.Roles;
import cn.webrx.entity.Users;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

/**
 * <p>Project: mybatis2021 - RolesMapper
 * <p>Powered by webrx On 2021-07-23 14:26:57
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 15
 */
public interface RolesMapper {
    @Select("select * from w_roles where name = #{name}")
    @Results(id = "rolesmap", value = {
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "users", column = "id", many = @Many(select = "selrole", fetchType = FetchType.LAZY))
    })
    public Roles queryByName(String name);

    @Select("select wr.id,wr.name,wr.password from w_users_roles wu join w_users wr on wu.role_id = ${id} and wr.id = wu.user_id")
    public List<Map<String, Object>> selrole(int id);

    @Select("select * from w_roles")
    @ResultMap("rolesmap")
    public List<Roles> queryAll();
}
